package com.amap.activity;

import java.util.ArrayList;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.amap.adapter.LocationAdapter;
import com.amap.controller.ApplicationController;
import com.amap.model.Location;
import com.amap.model.Place;

public class LocationListView extends ListActivity implements OnItemClickListener {
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState); 	 
  	 
	  Location loc = new Location(Double.parseDouble("-8.051411"), Double.parseDouble("-34.950385"));
	 // Location loc = ApplicationController.getInstance().getUserLoc();
	  
	  Intent i = getIntent();
	  
	  final ArrayList<Place> places =  ApplicationController.getInstance().getLocations(loc ,"5000", "food", i.getStringExtra("nameUrl"));
	  
	  LocationAdapter locationAdapter = new  LocationAdapter(this, places);
	  
	  ListView listView = getListView();
	  listView.setTextFilterEnabled(true);
	  listView.setOnItemClickListener(this);
	  listView.setAdapter(locationAdapter);
	  
	}

	@Override
	public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {

		Place place = ApplicationController.getInstance().getPlaceById(position);
		
		String s = "http://maps.google.com/maps?saddr=-8.051411,-34.950385&daddr="+
				    place.getLocation().getLatitude() + "," + place.getLocation().getLongitude()+"";
		
		Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse((String) s));
		startActivity(intent);
		
		
	}
	
	
}
